package com.suning.app.snpaasadmin.action;

import com.opensymphony.xwork2.ActionSupport;
import com.suning.app.snpaasadmin.api.CfVersionAPI;
import com.suning.app.snpaasadmin.pojo.CfVersion;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

public class CfVersionAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private Map<String, Object> dataMap;
	
	private File file;
	
	private Integer type;
	

	/**
	 * 
	 * 功能描述: <br>
	 * 获取cf版本 get method
	 *
	 * @return
	 * @throws Exception
	 * @see [相关类/方法](可选)
	 * @since [产品/模块版本](可选)
	 */
	public String getCfVersion() throws Exception {
		dataMap = new HashMap<String, Object>();
		HttpServletRequest request = ServletActionContext.getRequest();
        HttpSession session  = request.getSession();
		List<CfVersion> cvList = CfVersionAPI.getCfVersion(session, type);
		dataMap.put("data", cvList);
		dataMap.put("success", true);
		return SUCCESS;
	}
	
	public String uploadCfVersion() throws Exception {
	    dataMap = new HashMap<String, Object>();
        HttpServletRequest request = ServletActionContext.getRequest();
        HttpSession session  = request.getSession();
        try {
            CfVersionAPI.uploadCfVesionApi(session, getFile());
            dataMap.put("success", true);
        } catch (Exception e) {
            dataMap.put("success", false);
            e.printStackTrace();
        }
	    return SUCCESS;
	}

    /**
     * @return the dataMap
     */
    public Map<String, Object> getDataMap() {
        return dataMap;
    }


    /**
     * @param dataMap the dataMap to set
     */
    public void setDataMap(Map<String, Object> dataMap) {
        this.dataMap = dataMap;
    }

    /**
     * @return the file
     */
    public File getFile() {
        return file;
    }

    /**
     * @param file the file to set
     */
    public void setFile(File file) {
        this.file = file;
    }

    /**
     * @return the type
     */
    public Integer getType() {
        return type;
    }

    /**
     * @param type the type to set
     */
    public void setType(Integer type) {
        this.type = type;
    }

}
